import 'package:flutter/material.dart';
import 'package:jd_shopping/services/ScreenAdaper.dart';
import 'package:jd_shopping/pages/Coustom/JdButton.dart';

class Pay extends StatefulWidget {
  @override
  _PayState createState() => _PayState();
}

class _PayState extends State<Pay> {
  List payList = [
    {
      "title": "支付宝支付",
      "chekced": true,
      "image": "https://www.itying.com/themes/itying/images/alipay.png"
    },
    {
      "title": "微信支付",
      "chekced": false,
      "image": "https://www.itying.com/themes/itying/images/weixinpay.png"
    }
  ];
  @override
  Widget build(BuildContext context) {
    ScreenAdaper.init(context);
    return Scaffold(
        appBar: AppBar(title: Text('支付')),
        body: Column(
          children: <Widget>[
            Container(
              height: ScreenAdaper.height(300),
              child: ListView.builder(
                  itemCount: payList.length,
                  itemBuilder: (context, index) {
                    return Column(
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.all(ScreenAdaper.height(10)),
                          child: ListTile(
                            leading: Image.network(
                              '${this.payList[index]['image']}',
                              fit: BoxFit.cover,
                            ),
                            title: Text('${this.payList[index]['title']}'),
                            trailing: Icon(this.payList[index]["chekced"]
                                ? Icons.check
                                : null),
                            onTap: () {
                              setState(() {
                                for (var i = 0; i < this.payList.length; i++) {
                                  this.payList[i]['chekced'] = false;
                                }
                                this.payList[index]['chekced'] = true;
                              });
                            },
                          ),
                        ),
                        Divider(height: 1),
                      ],
                    );
                  }),
            ),
            SizedBox(height: 10),
            JdButton(
              color: Colors.red,
              text: '支付',
              cb: () {
                print('123');
              },
            )
          ],
        ));
  }
}
